package edu.software.cakehomework.service.impl;

import edu.software.cakehomework.dao.MenuRepository;
import edu.software.cakehomework.entity.Menu;
import edu.software.cakehomework.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuRepository menuRepository;

    @Override
    public Page<Menu> getMenusByCategory(String category, Pageable pageable) {
        return menuRepository.findByCategory(category, pageable);
    }

    @Override
    public Page<Menu> searchMenus(String keyword, Pageable pageable) {
        return menuRepository.searchByKeyword(keyword, pageable);
    }

    @Override
    public List<Menu> getAvailableMenus() {
        return menuRepository.findByIsAvailableTrue();
    }

    @Override
    public List<String> getAllCategories() {
        return menuRepository.findAllCategories();
    }

    @Override
    public Menu getMenuById(Integer id) {
        return menuRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("Menu not found"));
    }
}